<?php

namespace App\Services\My;

use App\Lib\Util\ErrorCode;
use App\Models\Admin\MenuModel;


/**
 * Class RoutesService
 * @package App\Services\My
 */
class RoutesService
{
  private $MenuModel;

  public function __construct(MenuModel $MenuModel)
  {
    $this->MenuModel = $MenuModel;
  }

  /**
   * 获取角色信息
   * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
   * @throws \Exception
   */
  public function getRoutesList()
  {
    $arrRoleInfo = $this->MenuModel::query()->where('parent',0)->with(
      [
        'children' => function ($query) {
          $query->select('*')->with(['children'=> function ($query) {
            $query->select('*')->with(['children']);
          }]);
        }
      ]
    )->get();
    if (empty($arrRoleInfo)) {
      throw new \Exception('', ErrorCode::NO_DATA);
    }

    $arrRoleInfo = array();
    $arrRoleInfo= array(
      'path'=>'/tab',
      'component'=>'Layout',
      'children'=>array(
        array(
          'path'=>'index',
          'component'=>'views/tab/index',
          'name'=>'Tab',
          'meta'=>array(
            'title'=>'tab组件',
            'icon'=>'tab'
          ),
        )
      ),
    );

    return $arrRoleInfo;
  }

}
